﻿// (c) Copyright slimCODE Software Inc. - www.slimcode.com
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Security.Cryptography;

namespace SlimCode.Utils
{
  public class HMACSHA512 : HMAC
  {
    private bool m_useLegacyBlockSize = false;

    public HMACSHA512() 
      : this( HMAC.GenerateRandom( 128 ) ) 
    {
    }

    public HMACSHA512( byte[] key )
    {
      m_hashName = "SHA512";
      m_hash1 = new SHA512Managed();
      m_hash2 = new SHA512Managed();

      this.HashSizeValue = 512;
      this.BlockSizeValue = BlockSize;

      this.InitializeKey( key );
    }

    private int BlockSize
    {
      get { return m_useLegacyBlockSize ? 64 : 128; }
    }

    public bool ProduceLegacyHmacValues
    {
      get { return m_useLegacyBlockSize; }
      set
      {
        m_useLegacyBlockSize = value;

        this.BlockSizeValue = this.BlockSize;
        this.InitializeKey( m_key );
      }
    }
  }
}
